package com.gl.rent;

import cn.hutool.core.convert.Convert;
import com.gl.common.util.SecurityUtils;
import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.dto.MetroStationDTO;
import com.haixiaoke.saas.repository.pojo.MetroStation;
import com.haixiaoke.saas.repository.service.IMetroStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地铁车站Controller
 * 
 * @author haixiaoke
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/base/metro/station")
public class MetroStationController extends BaseController {
    @Autowired
    private IMetroStationService metroStationService;

    /**
     * 查询地铁车站列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MetroStation metroStation) {
        startPage();
        List<MetroStation> list = metroStationService.selectMetroStationList(metroStation);
        return getDataTable(list);
    }


    /**
     * 获取地铁车站详细信息
     */
    @GetMapping(value = "/{stationId}")
    public AjaxResult getInfo(@PathVariable("stationId") Long stationId) {
        return success(metroStationService.selectMetroStationByStationId(stationId));
    }

    /**
     * 新增地铁车站
     */
    @PostMapping
    public AjaxResult add(@RequestBody MetroStationDTO metroStation) {

        //填写修改人
        String id = Convert.toStr(SecurityUtils.getLoginUserId());
        metroStation.setCreateBy(id);

        return toAjax(metroStationService.insertMetroStation(metroStation));
    }

    /**
     * 修改地铁车站
     */
    @PutMapping
    public AjaxResult edit(@RequestBody MetroStation metroStation) {
        //填写修改人
        String id = Convert.toStr(SecurityUtils.getLoginUserId());
        metroStation.setUpdateBy(id);

        return toAjax(metroStationService.updateMetroStation(metroStation));
    }

    /**
     * 删除地铁车站
     */
	@DeleteMapping("/{stationIds}")
    public AjaxResult remove(@PathVariable Long[] stationIds) {
        return toAjax(metroStationService.softDeleteMetroStationByStationIds(stationIds));
    }
}
